<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('购煤记录')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <input type="hidden" id="villageId" name="villageId" th:value="${villageId}">
        <div class="row">
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jjm:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jjm:order:remove')}]];
        var statusDatas = [[${@dict.getType('order_status')}]];
        var prefix = ctx + "jjm/order";

        $(function() {
            var options = {
                url: prefix + "/list?villageId="+$("#villageId").val(),
                createUrl: prefix + "/add",
                confirmUrl: prefix + "/confirm/{id}",
                exportUrl: prefix + "/export",
                modalName: "供应商订单",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                columns: [
                {
                    field: 'id',
                    title: 'null',
                    visible: false
                },
                {
                    field: 'supplier.name',
                    title: '供应商'
                },
                {
                    field: 'supplier.phoneNumber',
                    title: '供应商电话'
                },
                {
                    field: 'createTime',
                    title: '提交订单日期',
                    formatter: function(value, row, index) {
                        return new Date(value).format("yyyy-MM-dd");
                    }
                },
                {
                    field: 'amount',
                    title: '购煤数量（吨）'
                },
                {
                    field: 'money',
                    title: '购煤款'
                },
                {
                    field: 'address',
                    title: '地址'
                },
                {
                    field: 'statusValue',
                    title: '订单状态'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status){
                            //已发货，确认收煤
                            if(row.status == 3){
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="confirm(\'' + row.id + '\')">确认收煤</a> ');
                            }else if(row.status == 4){
                                actions.push('<span class="btn btn-default btn-xs">'+new Date(row.confirmTime).format("yyyy-MM-dd")+'收到煤</span>&nbsp;');
                            }
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function confirm(id) {
            table.set();
            $.modal.confirm("您确认已收到煤吗？", function() {
                var url = $.common.isEmpty(id) ? table.options.confirmUrl : table.options.confirmUrl.replace("{id}", id);
                if(table.options.type == table_type.bootstrapTreeTable) {
                    $.operate.get(url);
                } else {
                    var data = { "id": id };
                    $.operate.submit(url, "post", "json", data);
                }
            });

        }
    </script>
</body>
</html>